package com.scada.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.scada.dao.IMenuAndPermissionDao;
import com.scada.dao.IMenuDao;
import com.scada.inf.MenuVisitor;
import com.scada.model.bean.SysMenu;
import com.scada.model.bean.vo.MenuVO;
import com.scada.model.result.ResponseBean;

@Service("menuVisitorService")
@WebService
@SOAPBinding(style = Style.RPC)
public class MenuVisitorImpl implements MenuVisitor{

	@Autowired
	private IMenuDao iMenuDao;
	@Autowired
	private IMenuAndPermissionDao iMenuAndPermissionDao;
	
	@Override
	public List<SysMenu> selectMenuIsleaf(Map<String, Object> map) {
		
		return iMenuDao.selectMenuIsleaf(map);
	}
	
	@Override
	public List<SysMenu> findLeftMenuByUser(Integer userId){
//		//查询PID为0的菜单
//		List<Integer> noParentMenuId = iMenuDao.findLeftMenuByUserIdNoParent(userId);
//		//查询PID不为0的父级菜单ID
//		List<Integer> parentMenuId = iMenuDao.findLeftMenuByUserIdParent(userId);
//		noParentMenuId.addAll(parentMenuId);
		return iMenuDao.findFirstMenuByRole(userId);
	}

	@Override
	public List<MenuVO> selectMenuList(Map<String, Object> map) {
		
		return iMenuDao.selectMenuList(map);
	}
	
	@Override
	public List<MenuVO> findLeftMenuById(Integer userId, Integer id){
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("userId", userId);
		map.put("id", id);
//		return iMenuDao.findLeftMenuById(map);
		return iMenuDao.findLeftMenuByPid(map);
	}
	
	@Override
	public List<SysMenu> selectAllData(int state) {
		
		return iMenuDao.selectAllData(state);
	}
	
	public ResponseBean selectAllMenuAndPermission(){
		ResponseBean rb = new ResponseBean();
		try {
			rb.addObject("menuAndPerList", iMenuAndPermissionDao.selectAllMenuAndPermission());
			rb.success();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rb;
	}

}
